package fe;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

import utils.Utils;

public class FeatureConfig {
	public enum FeatureType{BASELINE, USELESS, PRODUCTION};
	private ArrayList<String> featureNames = new ArrayList<String>();
	private ArrayList<FeatureType> featureTypes = new ArrayList<FeatureType>();
	public FeatureConfig(String configPath) throws IOException{
		BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(configPath)));
		String line;
		while ((line = bufferedReader.readLine()) != null) {
			if (!Utils.isValid(line))
				continue;
			String[] values = line.trim().split(FEATURE_CONFIG_SEPARATOR);
			featureNames.add(values[0]);
			if (values[1].equalsIgnoreCase("b"))
				featureTypes.add(FeatureType.BASELINE);
			else if (values[1].equalsIgnoreCase("u"))
				featureTypes.add(FeatureType.USELESS);
			else
				featureTypes.add(FeatureType.PRODUCTION);			
		}
	}
	
	public ArrayList<String> getFeatureNames() {
		return featureNames;
	}
	
	public ArrayList<FeatureType> getFeatureTypes() {
		return featureTypes;
	}
	
	public static final String FEATURE_CONFIG_NAME = "feature_config";
	public static final String FEATURE_CONFIG_SEPARATOR = "\t";
	public static final String DEFAULT_CONFIG_PATH = "conf/features.conf";
	
	public String getFeatureConfig(){
		StringBuilder builder = new StringBuilder();		
		for (int i = 0; i < featureNames.size(); ++i) {
			builder.append(featureNames.get(i));
			if (i != featureNames.size() - 1)
				builder.append(FEATURE_CONFIG_SEPARATOR);
		}
		return builder.toString().trim();
	}
}
